package com.hmall.search.web;

import com.hmall.common.clients.UserClient;
import com.hmall.common.dto.Address;
import com.hmall.common.dto.PageDTO;
import com.hmall.search.pojo.ItemDoc;
import com.hmall.search.pojo.PageResult;
import com.hmall.search.pojo.RequestParams;
import com.hmall.search.service.SearchService;
import org.checkerframework.checker.nullness.qual.AssertNonNullIfNonNull;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/search")
public class HMAllController {

    @Autowired
    private UserClient userClient;

    @Autowired
    private SearchService searchService;

    @PostMapping("/list")
    public PageDTO<ItemDoc> search(@RequestBody RequestParams params){
        PageDTO<ItemDoc> pageDTO= searchService.search(params);
        return pageDTO;
    }

    @GetMapping("/suggestion")
    public List<String> getSuggestion(@RequestParam("key") String prefix){
        return searchService.getSuggestion(prefix);
    }


    @PostMapping("/filters")
    public Map<String,List<String>> filters(RequestParams params){
        Map<String,List<String>> map = searchService.filters(params);
        return map;
    }


}
